<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../layui/layui.js"></script>
    <script src="../js/jquery-1.8.0.min.js"></script>
    <script src="../js/ajax.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../css/addPage.css">
</head>

<body>
    <form action="" class="layui-form layui-form-pane">
        <input type="hidden" name="id" id="id" placeholder="请输入标题" autocomplete="off" class="layui-input">
        <div class="layui-form-item">
            <label class="layui-form-label">人员编号</label>
            <div class="layui-input-block">
                <input type="text" name="staffId" maxlength="30" id="staffId" required lay-verify="required"
                    placeholder="请输入人员编号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">人员名称</label>
            <div class="layui-input-block">
                <input type="text" name="staffName" maxlength="30" id="staffName" required lay-verify="required"
                    placeholder="请输入人员名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">人员密码</label>
            <div class="layui-input-block">
                <input type="text" name="staffPwd" maxlength="30" id="staffPwd" required lay-verify="required"
                    placeholder="请输入人员密码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">入职时间</label>
            <div class="layui-input-block">
                <input type="text" name="entryTime" maxlength="30" id="entryTime" required lay-verify="required"
                    placeholder="请选择入职时间" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">部门</label>
            <div class="layui-input-block">
                <select name="departmentId" id="departmentId" lay-search="">
                    <option value=""></option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="send" lay-submit lay-filter="AddOrUpdate">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script src="../js/host.js"></script>
    <script>

        $.ajaxSetup({
            headers: {
                "token": localStorage.getItem("token")
            }
        });

        $(function () {
            layui.use(["table", "form"], function () {
                var table = layui.table;
                var form = layui.form;
                var laydate = layui.laydate;
                //日期
                laydate.render({
                    elem: '#entryTime'
                });

                setTimeout(function () {
                    form.render("select")
                }, 50)
                $.ajaxSettings.async = false;

                new ajax(host + "/getDepartment", "get", {}, "json", function (data) {
                    $.each(data, function (index, item) {
                        $("#departmentId").append("<option value='" + item.id + "'>" + item.departmentName + "</option>")
                    })
                    form.render("select")
                });

                form.on("submit(AddOrUpdate)", function (data) {
                    var url = "addStaff";
                    if ($("#id").val() != null && $("#id").val() != "") {
                        url = "updateStaff";
                    }

                    new ajax(host + "/" + url, "get", data.field, "json", function (data) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.layer.msg('提交成功', {
                            icon: 1,
                            time: 2000
                        });
                    });
                    $.ajaxSettings.async = true;
                    return false;
                })

            })
        })
    </script>
</body>

</html>